-- VGA Character Memory
--
-- This memory can store 128x32 characters where each character is
-- 8 bits. The memory is dual ported providing a port
-- to read the characters and a port to write the characters.
--
-- 

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity video_ram is
   port(
      clk: in std_logic;
      vram_read_addr : in std_logic_vector(7 downto 0);
      vram_write_addr: in std_logic_vector(7 downto 0);
      vram_we : in std_logic;
      vram_write_value : in std_logic_vector(7 downto 0);
      vram_read_value : out std_logic_vector(7 downto 0)
   );
end video_ram;

architecture arch of video_ram is

   constant VRAM_ADDR_WIDTH: integer := 8; -- 2^7 X 2^5
   constant VRAM_WIDTH: integer := 8;  -- 8 bits per coordinate
   type vram_type is array (0 to 2**VRAM_ADDR_WIDTH-1)
     of std_logic_vector(VRAM_WIDTH-1 downto 0);
   signal read_a : std_logic_vector(7 downto 0);

   -- character memory signal
   signal vram : vram_type;
begin

  -- character memory concurrent statement
  process(clk)
  begin
    if (clk'event and clk='1') then
      if (vram_we = '1') then
        vram(to_integer(unsigned(vram_write_addr))) <= vram_write_value;
      end if;
      read_a <= vram_read_addr;
    end if;
  end process;
  vram_read_value <= vram_ram(to_integer(unsigned(read_a)));
     
end arch;

